#include <iostream>
#include <string>
#include <unistd.h>

#include "timer.h"
using namespace std;

int add(int a, int b)
{
    return a + b;
}

template<typename F, typename... Arg>
void testFunc(F&& f, Arg&&... args)
{
    ThreadPool pool;
    std::function<int()> fun = std::bind(std::forward<F>(f), std::forward<Arg>(args)...);

    auto b = pool.EnQueue(fun);
    printf("res = %d\n", b.get());
}

void testThredPool()
{
    ThreadPool pool;
    cout << "thread num = " << pool.GetThreadNum() << endl;

    std::future<int> res1 = pool.EnQueue(add, 1, 1);
    pool.EnQueue([](){
        cout << "hello world" << endl;
    });

    pool.EnQueue([](const string& str){
        cout << str << endl;
    }, "lalala");

    printf("res1 = %d\n", res1.get());

    testFunc(add, 1, 2);
}

//========================================================================================

void Test(int a = 1, int b = 1)
{
    cout << "a + b = " << a + b << endl;
}

void Test2()
{
    cout << "hello world" << endl;
}

void TestTimer()
{
    TimerManager timer(2);


    timer.AddTask(1000, false, [](){
        cout << "hello world" << endl;
    });

    Timer::ptr t1 = timer.AddTask(500, true, [](std::string str){
        cout << "str = " << str << endl;
    }, "lalala");
    
    Timer::ptr t2 = timer.AddTask(2000, true, Test, 2, 2);

    sleep(10);

    
    t1->Stop();
    t2->Stop();
}

int main(void)
{
    // testThredPool();
    TestTimer();

    cout << "heiheihei" << endl;

    return 0;
}

